package com.panshi.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panshi.modules.system.bean.BeiSysRole;
import com.panshi.modules.system.bean.BeiSysUser;
import com.panshi.modules.system.bean.SysRoleFunction;
import com.panshi.modules.system.mapper.BeiSysRoleMapper;
import com.panshi.modules.system.service.BeiSysRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 角色表  服务实现类
 * </p>
 *
 * @author 小伍
 * @since 2020-08-07
 */
@Service
public class BeiSysRoleServiceImpl  implements BeiSysRoleService {

    @Autowired
    private BeiSysRoleMapper beiSysRoleMapper;
    @Override
    @Cacheable(value = "role",  key = "targetClass + methodName +#uadi")
    public List<BeiSysRole> queryall(int uadi) {
        return beiSysRoleMapper.queryall(uadi);
    }

    @Override
    @Cacheable(value = "role", key = "#root.methodName")
    public List<BeiSysRole> query(Map<String, Integer> map) {
        Page<BeiSysRole> page = new Page(map.get("currentPage"),map.get("pageSize"));
        QueryWrapper<BeiSysRole> user=new QueryWrapper<>();
        beiSysRoleMapper.selectPage(page, user);
        return page.getRecords();
    }

    @Override
    @Cacheable(value = "role", key = "#root.methodName")
    public Integer querySysRoleCount() {
        QueryWrapper<BeiSysRole> user=new QueryWrapper<>();
        user.isNotNull("rid");
        return beiSysRoleMapper.selectCount(user);
    }

    @Override
    @Cacheable(value = "role", key = "#root.methodName")
    public List<BeiSysRole> querys() {
        return beiSysRoleMapper.selectList(null);
    }

    @Override
    @CacheEvict(value="role",allEntries=true)
    public void updateRoleBystate(BeiSysRole beiSysRole) {
        beiSysRoleMapper.updateById(beiSysRole);
    }

    @Override
    @CacheEvict(value="role",allEntries=true)
    public Integer addrole(BeiSysRole beiSysRole) {
        beiSysRoleMapper.insert(beiSysRole);
        return beiSysRole.getRid();
    }

    @Override
    @CacheEvict(value="role",allEntries=true)
    public void addSysRoleFunction(SysRoleFunction sysRoleFunction) {
        beiSysRoleMapper.addSysRoleFunction(sysRoleFunction);
    }

    @Override
    @CacheEvict(value="role",allEntries=true)
    public void updateSysRole(BeiSysRole beiSysRole) {
        beiSysRoleMapper.updateById(beiSysRole);
    }

    @Override
    @CacheEvict(value="role",allEntries=true)
    public void deleteSysRole(int rid) {
        beiSysRoleMapper.deleteById(rid);
    }
}
